package com.lagou.service.impl;


import com.lagou.base.StatusCode;
import com.lagou.dao.CourseDao;
import com.lagou.dao.impl.CourseDaoImpl;
import com.lagou.pojo.Course;
import com.lagou.service.CourseService;
import com.lagou.utils.DateUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CourseServiceImpl implements CourseService {
    CourseDao dao = new CourseDaoImpl();

    public List<Course> findCourseList() {
        List<Course> courseList = dao.findCourseList();
        return courseList;
    }

    public List<Course> findByCourseNameAndStatus(String courseName, String status) {

        List<Course> byCourseNameAndStatus = dao.findByCourseNameAndStatus(courseName, status);
        return byCourseNameAndStatus;
    }

    public String saveCourseSalesInfo(Course course) {
        // 补全课程营销信息
        String dateFormart = DateUtils.getDateFormart();
        course.setCreate_time(dateFormart);
        course.setUpdate_time(dateFormart);
        course.setStatus(1);
        int i = dao.saveCourseSalesInfo(course);
        if(i>0){
            String str1= StatusCode.SUCCESS.toString();
            return str1;
        }else {
            String str2 = StatusCode.FAIL.toString();
            return str2 ;
        }
    }

    @Override
    public Course findCourseById(int id) {
        Course course = dao.findCourseById(id);
        return course;
    }

    @Override
    public String updateCourseSalesInfo(Course course) {
        int row = dao.updateCourseSalesInfo(course);
        if(row>0){
            String str1= StatusCode.SUCCESS.toString();
            return str1;
        }else{
            String str2 = StatusCode.FAIL.toString();
            return str2;
        }

    }

    @Override
    public Map<String, Integer> updateCourseStatus(Course course) {
        int row = dao.updateCourseStatus(course);
        Map<String,Integer> map = new HashMap<>();
        if(row>0){
            if (course.getStatus()==0){
                map.put("status",0);
            }else{
                map.put("status",1);
            }
        }
        return map;
    }


}
